<?php

namespace app\model\video;

use app\model\BaseModel;

/**
 * @property integer $pro_video_id ID(主键)
 * @property string $title 标题
 * @property string $subtitle 副标题
 * @property string $sale_price 销售价
 * @property string $origin_price 原价
 * @property string $vid 腾讯视频id
 * @property string $main_image 
 * @property string $sort 排序
 * @property integer $status 状态
 * @property integer $isdel 是否删除 1是 0否
 * @property string $created_at 添加时间
 * @property string $updated_at 最后更新时间
 * @property integer $is_check 审核数据
 */
class ProductionVideo extends BaseModel
{
    protected $table = 'ting_production_video';

    protected $primaryKey = 'pro_video_id';

    protected static $instance;

    public static function getInstance()
    {
        if(is_object(self::$instance)){
            return self::$instance;
        }

        self::$instance = new self();

        return self::$instance;
    }

    public function index($where, $field=[],$order = [])
    {
        $query = $this->getWhere($where);

        $field && $query->select($field);

        $data = $this->buildPage($query);
        $order && is_array($order) && $query->orderBy($order[0],$order[1]);
        $order && is_string($order) && $query->orderBy(Db::raw($order));
        $query->orderBy('pro_video_id','desc');

        $data['data'] = $query->get();

        return $data;
    }

    public function getDetail($where,$field=[])
    {
        $query = $this->where($where);
        $field && $detail = $query->select($field);
        $detail =  $query->first();

        if($detail==false){
            throw new UserException(4000);
        }

        return $detail;
    }




}
